public without sharing class testController{
    public List<ContractProduct__c> cpList {get;set;}
    public String conid ;
    public String html {get;set;}
    public testController(){

    		//conid = System.currentPageReference().getParameters().get('id');
    		//cpList = new List<ContractProduct__c>();

    }

    public class IntentProductBean{
        @AuraEnabled
        public String intentProductId ; 
        @AuraEnabled
        public Product__c product;
        @AuraEnabled
        public Boolean chk;
    

    }
    @AuraEnabled
    public static List<IntentProductBean>  initProduct(String oppId){

        List<IntentProductBean> tmp = new List<IntentProductBean>();

        for(IntentProduct__c ip : [select Id ,Product__c,Product__r.ProductName__c , Product__r.NCCode__c,
            Product__r.Brand__c,SpecialTeam__c,SpecialTeam__r.Name 
          from IntentProduct__c where Opportunity__c =:oppId ]){


                IntentProductBean ipb = new IntentProductBean();
                ipb.intentProductId = ip.Id ; 
                ipb.product =(Product__c) ip.getSObject('Product__r');
                ipb.chk = false;
                tmp.add(ipb);
            
        }
        return tmp ; 
    }
    public void init(){
    	List<ContractProductBean> tmp = new List<ContractProductBean>();
    	for(ContractProduct__c cp :[select Id,Name ,Product__r.Name ,Product__r.Brand__c, SalesPrice__c from ContractProduct__c where Contract__c =:conid]){

    		tmp.add(new ContractProductBean(cp));
    	}
    	html = EncodingUtil.urlEncode(JSON.serialize(tmp), 'UTF-8');
    	
     //    //请求Hr数据，获取系统内ID
     //    HttpRequest request = new HttpRequest();
     //    request.setMethod('GET');
     //    request.setEndpoint('https://esb.maccura.com:9088/api/Domain/TimeTask/fw/hr?userID=2683');
     //    HttpResponse response =  Utils.postRequest(request,2);
     //    Map<String,Object> m = (Map<String,Object>)JSON.deserializeUntyped(response.getBody()); 
     //    String jsr = (String)m.get('result');
     //    //格式化
     //    Pattern p = Pattern.compile('\\s*|\t|\r|\n');
     //    Matcher m_jsr = p.matcher(jsr);
     //    String n_jsr = m_jsr.replaceAll('');
     //    String xml_o = n_jsr.replace('<UserBean-array>', '');
     //    String n_xml = xml_o.replace('</UserBean-array>', '');
     //    System.debug(n_xml);
     //    //XML解析
     //    Dom.Document doc = new Dom.Document(); 
     //    doc.load(n_xml);
     //    Dom.XMLNode userDataInfo = doc.getRootElement();
     //    String userid = userDataInfo.getChildElement('userid', null).getText(); 
     //    String subcompanyid = userDataInfo.getChildElement('subcompanyid1', null).getText();
     //    String departmentid = userDataInfo.getChildElement('departmentid', null).getText();
     //    //设置创建审批流请求所需参数
    	// webservicesWorkflowWeaver.WorkflowRequestInfo  wk = new webservicesWorkflowWeaver.WorkflowRequestInfo ();
    	// wk.requestName = '测试合同流程';
     //    wk.requestLevel = '0';
    	// wk.creatorId = userid;
     //    //流程基础信息
     //    webservicesWorkflowWeaver.WorkflowBaseInfo wbf = new webservicesWorkflowWeaver.WorkflowBaseInfo();
     //    wbf.workflowId = '385';
     //    wbf.workflowName = '流程名称';
     //    wbf.workflowTypeName = '流程类型名称';
     //    wk.workflowBaseInfo = wbf;

     //    /***********************主表参数开始************************/
     //    webservicesWorkflowWeaver.WorkflowMainTableInfo wmtf = new webservicesWorkflowWeaver.WorkflowMainTableInfo();
     //    webservicesWorkflowWeaver.WorkflowRequestTableField[] wrtfs = new List<webservicesWorkflowWeaver.WorkflowRequestTableField>();
     //    /*申请人*/
     //    webservicesWorkflowWeaver.WorkflowRequestTableField wrtf0 = new webservicesWorkflowWeaver.WorkflowRequestTableField();
     //    wrtf0.fieldName = 'sqr';
     //    wrtf0.fieldValue = userid;
     //    wrtf0.edit = true;
     //    wrtf0.view = true;
     //    wrtfs.add(wrtf0);
     //    /*所属部门*/
     //    webservicesWorkflowWeaver.WorkflowRequestTableField wrtf1 = new webservicesWorkflowWeaver.WorkflowRequestTableField();
     //    wrtf1.fieldName = 'ssbm';
     //    wrtf1.fieldValue = departmentid;
     //    wrtf1.edit = true;
     //    wrtf1.view = true;
     //    wrtfs.add(wrtf1);
     //    /*所属公司*/
     //    webservicesWorkflowWeaver.WorkflowRequestTableField wrtf2 = new webservicesWorkflowWeaver.WorkflowRequestTableField();
     //    wrtf2.fieldName = 'ssgs';
     //    wrtf2.fieldValue = subcompanyid;
     //    wrtf2.edit = true;
     //    wrtf2.view = true;
     //    wrtfs.add(wrtf2);
     //    /*合同名称*/
     //    webservicesWorkflowWeaver.WorkflowRequestTableField wrtf3 = new webservicesWorkflowWeaver.WorkflowRequestTableField();
     //    wrtf3.fieldName = 'htmc';
     //    wrtf3.fieldValue = 'salesforce发起-测试合同';
     //    wrtf3.edit = true;
     //    wrtf3.view = true;
     //    wrtfs.add(wrtf3);
     //    /*合同编号*/
     //    webservicesWorkflowWeaver.WorkflowRequestTableField wrtf4 = new webservicesWorkflowWeaver.WorkflowRequestTableField();
     //    wrtf4.fieldName = 'htbh';
     //    wrtf4.fieldValue = '9527';
     //    wrtf4.edit = true;
     //    wrtf4.view = true;
     //    wrtfs.add(wrtf4);
     //    /*合同开始时间*/
     //    webservicesWorkflowWeaver.WorkflowRequestTableField wrtf5 = new webservicesWorkflowWeaver.WorkflowRequestTableField();
     //    wrtf5.fieldName = 'kssj';
     //    wrtf5.fieldValue = '2018-08-07';
     //    wrtf5.edit = true;
     //    wrtf5.view = true;
     //    wrtfs.add(wrtf5);
     //    /*合同结束时间*/
     //    webservicesWorkflowWeaver.WorkflowRequestTableField wrtf6 = new webservicesWorkflowWeaver.WorkflowRequestTableField();
     //    wrtf6.fieldName = 'jssj';
     //    wrtf6.fieldValue = '2018-09-18';
     //    wrtf6.edit = true;
     //    wrtf6.view = true;
     //    wrtfs.add(wrtf6);
     //    /*合同金额*/
     //    webservicesWorkflowWeaver.WorkflowRequestTableField wrtf7 = new webservicesWorkflowWeaver.WorkflowRequestTableField();
     //    wrtf7.fieldName = 'xxzj';
     //    wrtf7.fieldValue = '18960';
     //    wrtf7.edit = true;
     //    wrtf7.view = true;
     //    wrtfs.add(wrtf7);
     //    /*我方主体*/
     //    webservicesWorkflowWeaver.WorkflowRequestTableField wrtf8 = new webservicesWorkflowWeaver.WorkflowRequestTableField();
     //    wrtf8.fieldName = 'wfzt';
     //    wrtf8.fieldValue = subcompanyid;
     //    wrtf8.edit = true;
     //    wrtf8.view = true;
     //    wrtfs.add(wrtf8);
     //    /*SF合同编号*/
     //    webservicesWorkflowWeaver.WorkflowRequestTableField wrtf9 = new webservicesWorkflowWeaver.WorkflowRequestTableField();
     //    wrtf9.fieldName = 'sfbh';
     //    wrtf9.fieldValue = 'a0I0k000002XeUl';
     //    wrtf9.edit = true;
     //    wrtf9.view = true;
     //    wrtfs.add(wrtf9);

     //    webservicesWorkflowWeaver.ArrayOfWorkflowRequestTableField awrtf = new webservicesWorkflowWeaver.ArrayOfWorkflowRequestTableField();
     //    awrtf.WorkflowRequestTableField = wrtfs;

     //    webservicesWorkflowWeaver.WorkflowRequestTableRecord wrtr= new webservicesWorkflowWeaver.WorkflowRequestTableRecord();
     //    wrtr.workflowRequestTableFields = awrtf;
        
     //    webservicesWorkflowWeaver.WorkflowRequestTableRecord[] wrtrs = new List<webservicesWorkflowWeaver.WorkflowRequestTableRecord>();
     //    wrtrs.add(wrtr);

     //    webservicesWorkflowWeaver.ArrayOfWorkflowRequestTableRecord awrtr = new webservicesWorkflowWeaver.ArrayOfWorkflowRequestTableRecord();
     //    awrtr.WorkflowRequestTableRecord =  wrtrs;

     //    wmtf.requestRecords = awrtr;
     //    wk.workflowMainTableInfo = wmtf;

     //    /***********************明细表参数开始************************/
     //    webservicesWorkflowWeaver.WorkflowDetailTableInfo wfdti = new webservicesWorkflowWeaver.WorkflowDetailTableInfo();
     //    webservicesWorkflowWeaver.WorkflowRequestTableField[] wrtfs_dt = new List<webservicesWorkflowWeaver.WorkflowRequestTableField>();
     //    /*合同相对方*/
     //    webservicesWorkflowWeaver.WorkflowRequestTableField wrtfdt0 = new webservicesWorkflowWeaver.WorkflowRequestTableField();
     //    wrtfdt0.fieldName = 'htxdf';
     //    wrtfdt0.fieldValue = '测试相对方';
     //    wrtfdt0.edit = true;
     //    wrtfdt0.view = true;
     //    wrtfs_dt.add(wrtfdt0);
     //    /*相对方联系人*/
     //    webservicesWorkflowWeaver.WorkflowRequestTableField wrtfdt1 = new webservicesWorkflowWeaver.WorkflowRequestTableField();
     //    wrtfdt1.fieldName = 'xdflxr';
     //    wrtfdt1.fieldValue = '小明';
     //    wrtfdt1.edit = true;
     //    wrtfdt1.view = true;
     //    wrtfs_dt.add(wrtfdt1);
     //    /*相对方联系方式*/
     //    webservicesWorkflowWeaver.WorkflowRequestTableField wrtfdt2 = new webservicesWorkflowWeaver.WorkflowRequestTableField();
     //    wrtfdt2.fieldName = 'xdflxfs';
     //    wrtfdt2.fieldValue = '12345678901';
     //    wrtfdt2.edit = true;
     //    wrtfdt2.view = true;
     //    wrtfs_dt.add(wrtfdt2);

     //    webservicesWorkflowWeaver.ArrayOfWorkflowRequestTableField awrtfdt = new webservicesWorkflowWeaver.ArrayOfWorkflowRequestTableField();
     //    awrtfdt.WorkflowRequestTableField = wrtfs_dt;

     //    webservicesWorkflowWeaver.WorkflowRequestTableRecord wrtrdt= new webservicesWorkflowWeaver.WorkflowRequestTableRecord();
     //    wrtrdt.workflowRequestTableFields = awrtfdt;

     //    webservicesWorkflowWeaver.WorkflowRequestTableRecord[] wrtrsdi = new List<webservicesWorkflowWeaver.WorkflowRequestTableRecord>();
     //    wrtrsdi.add(wrtrdt);

     //    webservicesWorkflowWeaver.ArrayOfWorkflowRequestTableRecord  awrtrdi = new webservicesWorkflowWeaver.ArrayOfWorkflowRequestTableRecord();
     //    awrtrdi.WorkflowRequestTableRecord = wrtrsdi;

     //    wfdti.workflowRequestTableRecords =  awrtrdi;

     //    webservicesWorkflowWeaver.WorkflowDetailTableInfo[]  wfdtis = new List<webservicesWorkflowWeaver.WorkflowDetailTableInfo>();
     //    wfdtis.add(wfdti);

     //    webservicesWorkflowWeaver.ArrayOfWorkflowDetailTableInfo  awdti = new webservicesWorkflowWeaver.ArrayOfWorkflowDetailTableInfo();
     //    awdti.WorkflowDetailTableInfo = wfdtis;

     //    wk.workflowDetailTableInfos = awdti;

     //    //发起请求
     //    webservicesServicesWeaverComCn.WorkflowServiceHttpPort wsh = new webservicesServicesWeaverComCn.WorkflowServiceHttpPort();
    	// String  requestId =  wsh.DoCreateWorkflowRequest(wk,Integer.valueOf(userid));
    	// System.debug(requestId);
    	

    }

    public class ContractProductBean{

    	public String productName ;
    	public String brand ;
    	public Decimal price ;
    	public ContractProductBean(ContractProduct__c cp ){
    		productName = cp.Product__r.Name;
    		brand = cp.Product__r.Brand__c;
    		price = cp.SalesPrice__c;
    	}
    }
}